package com.cgt.xiaotao.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cgt.xiaotao.product.domain.po.Product;
import com.cgt.xiaotao.product.domain.query.ProductPageQuery;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface ProductMapper extends BaseMapper<Product> {

    @Select("<script>" +
            "SELECT * FROM product " +
            "<where>" +
            "   <if test='query.tags != null and query.tags.size() > 0'>" +
            "       (" +
            "       <foreach collection='query.tags' item='tag' separator=' OR '>" +
            "           JSON_CONTAINS(tags, '\"${tag}\"')" +
            "       </foreach>" +
            "       )" +
            "   </if>" +
            "</where>" +
            "LIMIT #{offset}, #{pageSize}" +
            "</script>")
    List<Product> selectByTags(@Param("query") ProductPageQuery query,
                               @Param("offset") long offset,
                               @Param("pageSize") long pageSize);
}
